import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import { useCounterStore } from '@/stores/counter';

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [

    {
      path: '/',
      name: 'Login',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/Login/Login.vue'),
    },
        {
      path: '/home',
      name: 'home',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/Home.vue'),
      children:[
            {
      path: '/basicdata',
      name: 'basicdata',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/Basic/BasicData.vue'),
    },
    {
      path: '/coderule',
      name: 'coderule',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views//SystemSetup/CodeRule.vue'),
    },
        {
      path: '/CodeView',
      name: 'CodeView',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views//BasicData-LC/CodeView.vue'),
    },
     {
      path: '/WareHouserView',
      name: 'WareHouserView',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views//BasicData-LC/WareHouserView.vue'),
    },
    {
      path: '/OrderFormView',
      name: 'OrderFormView',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views//BasicData-LC/OrderFormView.vue'),
    },
     {
      path: '/Allot',
      name: 'Allot',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/StockControl-GJH/Allot.vue'),
    },
     {
      path: '/takestock',
      name: 'takestock',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/StockControl-GJH/takestock.vue'),
    },
        {
      path: '/inOuStatistics',
      name: 'inOuStatistics',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/Statistics-XKY/InOuStatistics.vue'),
    },
    {
      path: '/ledger',
      name: 'ledger',
      component: () => import('../views/ledger.vue')
    },
    {
      path: '/inventory-management',
      name: 'inventoryManagement',
      component: () => import('../views/InventoryManagement.vue')
    },
    {
      path: '/inventory-statistics',
      name: 'inventoryStatistics',
      component: () => import('../views/InventoryStatistics.vue')
    },
    {
      path: '/inventory-flow',
      name: 'inventoryFlow',
      component: () => import('../views/InventoryFlow.vue')
    }
,
    {
      path: '/orderform',
      name: 'orderform',
      component: () => import('../views/Basic/OrderForm.vue')
    }

      ]
    },
    
  ],
})


router.beforeEach((to, from, next) => {
  const a=useCounterStore();
if (to.name !== 'Login' && !a.islogin) {
next({ name: 'Login' });
} else {
next();
}
});

export default router
